float4x4 World;
float4x4 View;
float4x4 Projection;

// TODO: add effect parameters here.
float3 LightDir;
float3 CameraPos;
float3 DiffuseLight;
float3 SpecularLight;
float3 AmbientLight;
float SpecularPower;

//texture
texture DiffuseTexture;
sampler TextureSampler = sampler_state
{
	Texture = <DiffuseTexture>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float3 Normal : NORMAL0;
    float2 Texcoord : TEXCOORD0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float4 VertLitColor : COLOR0;
    float2 Texcoord : TEXCOORD0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    // TODO: add your vertex shader code here.
    output.Texcoord = input.Texcoord;
    
    float NL = dot(input.Normal, -LightDir);
    float3 Half = normalize(normalize(CameraPos - input.Position) - LightDir);
    float NH = dot(input.Normal, Half);
    float3 Diffuse = NL * DiffuseLight;
    float3 Specular = pow(NH * SpecularLight, SpecularPower);
    
	output.VertLitColor = float4(saturate(Diffuse + Specular) + AmbientLight, 1.0f);

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    // TODO: add your pixel shader code here.
	return input.VertLitColor * tex2D(TextureSampler, input.Texcoord);
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_1_1 VertexShaderFunction();
        PixelShader = compile ps_1_1 PixelShaderFunction();
    }
}
